package com.ruoyi.business.modbus.service;

import java.util.List;
import java.util.Map;
import com.ruoyi.business.modbus.domain.ModbusMasterDevice;
import com.ruoyi.business.modbus.domain.ModbusReadRequest;
import com.ruoyi.business.modbus.domain.ModbusReadResponse;
import com.ruoyi.business.modbus.domain.ModbusWriteResponse;

/**
 * Modbus核心服务接口 - 底层封装，不依赖数据库Device
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
public interface IModbusCoreService 
{
    /**
     * 测试设备连接
     * 
     * @param modbusMasterEntity Modbus主站实体配置
     * @param slaveAddress 从站地址
     * @return 连接结果
     */
    public ModbusReadResponse<Boolean> testConnection(ModbusMasterDevice modbusMasterEntity, int slaveAddress);

    /**
     * 读取保持寄存器
     * 功能码：0x03
     * 
     * @param modbusMasterEntity Modbus主站实体配置
     * @param slaveAddress 从站地址
     * @param startAddress 起始地址
     * @param quantity 数量
     * @return 读取结果
     */
    public ModbusReadResponse<Integer> readHoldingRegisters(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int startAddress, int quantity);

    /**
     * 读取输入寄存器
     * 功能码：0x04
     * 
     * @param modbusMasterEntity Modbus主站实体配置
     * @param slaveAddress 从站地址
     * @param startAddress 起始地址
     * @param quantity 数量
     * @return 读取结果
     */
    public ModbusReadResponse<Integer> readInputRegisters(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int startAddress, int quantity);

    /**
     * 读取线圈状态
     * 功能码：0x01
     * 
     * @param modbusMasterEntity Modbus主站实体配置
     * @param slaveAddress 从站地址
     * @param startAddress 起始地址
     * @param quantity 数量
     * @return 读取结果
     */
    public ModbusReadResponse<Boolean> readCoils(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int startAddress, int quantity);

    /**
     * 读取离散输入
     * 功能码：0x02
     * 
     * @param modbusMasterEntity Modbus主站实体配置
     * @param slaveAddress 从站地址
     * @param startAddress 起始地址
     * @param quantity 数量
     * @return 读取结果
     */
    public ModbusReadResponse<Boolean> readDiscreteInputs(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int startAddress, int quantity);

    /**
     * 写入单个线圈
     * 功能码：0x05
     */
    public ModbusWriteResponse writeSingleCoil(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int address, boolean value, boolean verify);

    /**
     * 写入多个线圈
     * 功能码：0x0F
     */
    public ModbusWriteResponse writeMultipleCoils(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int startAddress, List<Boolean> values, boolean verify);

    /**
     * 写入单个寄存器
     * 功能码：0x06
     */
    public ModbusWriteResponse writeSingleRegister(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int address, int value, boolean verify);

    /**
     * 写入多个寄存器
     * 功能码：0x10
     */
    public ModbusWriteResponse writeMultipleRegisters(ModbusMasterDevice modbusMasterEntity, int slaveAddress, int startAddress, List<Integer> values, boolean verify);

    /**
     * 获取设备连接状态
     * 
     * @param deviceSN 设备编码
     * @return 连接状态
     */
    public boolean getConnectionStatus(String deviceSN);

    /**
     * 获取设备统计信息
     * 
     * @param modbusMasterEntity Modbus主站实体配置
     * @return 统计信息
     */
    public Map<String, Object> getDeviceStatistics(ModbusMasterDevice modbusMasterEntity);

    /**
     * 获取连接池统计信息
     * 
     * @return 统计信息
     */
    public Map<String, Object> getConnectionPoolStatistics();

    /**
     * 获取实现信息
     * 
     * @return 实现信息
     */
    public Map<String, Object> getImplementationInfo();
}
